import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class tryList extends MIDlet implements CommandListener{
	private String avactor[] = {"苍井空","小泽玛丽亚","松岛枫","饭岛爱"};
	private String hlactor[] = {"莱昂那多","诺顿","囧瑟夫","布拉得"};
	private List aactor,hactor,type,menu;
	private Display dis ;
	private Command cmdback = new Command("back",Command.BACK,0);
	private Command cmdexit = new Command("exit",Command.EXIT,1);
	private Command cmdselect = new Command("select",Command.ITEM,2);
	private Command cmdok = new Command("ok",Command.OK,3);
	
	private Ticker ti = new Ticker("明星选择系统:");
	public tryList() {
		// TODO Auto-generated constructor stub
		menu = new List("type choice",List.IMPLICIT);
		aactor = new List("AV女星",List.MULTIPLE,avactor,null);
		hactor = new List("好莱坞男星",List.MULTIPLE,hlactor,null);
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		dis = Display.getDisplay(this);
		menu.append("AV女星", null);
		menu.append("好莱坞明星", null);
		menu.setSelectCommand(cmdselect);
		menu.addCommand(cmdexit);
		
		menu.setCommandListener(this);
		dis.setCurrent(menu);
	}

	public void commandAction(Command cmd, Displayable d) {
		// TODO Auto-generated method stub
		String choice;
		int index;
		if(cmd == cmdselect)
		{
			//选择
			index = menu.getSelectedIndex();
			choice = menu.getString(index);
			if(choice.equals("AV女星"))
			{
				
				aactor.addCommand(cmdback);
				aactor.addCommand(cmdok);
				aactor.addCommand(cmdexit);
				aactor.setCommandListener(this);
				dis.setCurrent(aactor);
			}
			else
			{
				hactor.addCommand(cmdback);
				hactor.addCommand(cmdok);
				hactor.addCommand(cmdexit);
				hactor.setCommandListener(this);
				dis.setCurrent(hactor);
			}
			
		}
		else if(cmd == cmdback)
		{
			//后退
			dis.setCurrent(menu);
		}
		else if(cmd == cmdok)
		{
			//确定
			int n;
			StringBuffer anwser = new StringBuffer();
			
			boolean flags [];
			List temp;
			if(d == aactor)
			{
				ti.setString("您选择了AV女星");
				d.setTicker(ti);
				//anwser.append("你选择了AV女星：");
				n = aactor.size();
				flags  = new boolean[n];
				aactor.getSelectedFlags(flags);
				temp = aactor;
			}
			else 
			{
				ti.setString("您选择了好莱坞女星");
				d.setTicker(ti);
//				anwser.append("你选择了好莱坞男星：");
				n = hactor.size();
				flags  = new boolean[n];
				hactor.getSelectedFlags(flags);
				temp = hactor;
			}
			
			for ( int i = 0; i < n ;i++ )
			{
				if(flags[i])
				{
					anwser.append('\n');
					
					anwser.append(temp.getString(i));
				}
			}
			TextBox tb = new TextBox("您的选择",anwser.toString(),100,TextField.ANY);
			tb.addCommand(cmdback);
			tb.addCommand(cmdexit);
			tb.setCommandListener(this);
			dis.setCurrent(tb);
			
		}
		else if(cmd == cmdexit)
		{
			notifyDestroyed();//退出
		}
	}

}
